<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c"
           uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.rapid-framework.org.cn/rapid" prefix="rapid" %>
<rapid:override name="head">
    <title>考试管理</title>
    <style>
        .btn-pink {
            background-color: #FFDAB9;
        }
        .line2{
            overflow : hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }

    </style>
</rapid:override>
<rapid:override name="content">
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    %>

    <script>
        function insert() {
            window.location.href="<%=basePath%>teacher/insertCourse";
        }
    </script>
    <table class="layui-table">
        <tr>
            <th width="100">试卷名: ${onlineExam.examName} <input type="hidden" id="examId" value="${onlineExam.examId}"/></th>
            <th width="100">包含题目总数: ${idsLenght}</th>
            <th width="100">包含题目总分: ${onlineExam.score}</th>
        </tr>
    </table>
    <table class="layui-table" style="margin-top:15px; background-color: rgba(255,218,185,0.5);
        color: #000;">
        <colgroup>
            <col width="50">
            <col width="300">
            <col width="50">
            <col width="50">
            <col width="100">
            <col width="100">
        </colgroup>

        <thead>
        <tr>
            <th><input type="checkbox" id="allCheck" />全选</th>
            <th>题目</th>
            <th>类型</th>
            <th>答案</th>
            <th>分值</th>
            <th>创建时间</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${paging.dataList}" var="question">
            <tr>

                <td>
                    <c:choose>
                        <c:when test="${question.isChoose == 1}">
                            已经选择
                        </c:when>
                        <c:otherwise>
                            <input type="checkbox" class="checkQuestion" value="${question.id}"/>
                        </c:otherwise>
                    </c:choose>

                </td>
                <td class="line2">${question.title}</td>
                <td>
                    <c:choose>
                        <c:when test="${question.type==1}">
                            单选
                        </c:when>
                        <c:when test="${question.type==2}">
                            多选
                        </c:when>
                        <c:when test="${question.type==3}">
                            填空
                        </c:when>
                        <c:when test="${question.type==4}">
                            判断
                        </c:when>
                        <c:when test="${question.type==5}">
                            问答
                        </c:when>
                    </c:choose>
                </td>
                <td class="line2">${question.answer}</td>
                <td>${question.score}</td>
                <td>${question.formateTime(question.createDate)}</td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <table class="layui-table">
        <colgroup>
            <col width="100">
            <col width="100">
            <col width="100">
        </colgroup>
        <tr>
            <th>
                <button type="button" onclick="addSubject()" class="layui-btn layui-btn-danger layui-btn-lg">
                    添加试题进试卷
                </button>
            </th>
            <th>
                <button type="button" onclick="sendExam()" class="layui-btn layui-btn-danger layui-btn-lg">
                    发布此考试
                </button>
            </th>
            <th>
                <button type="button" onclick="getExamRecord()" class="layui-btn layui-btn-danger layui-btn-lg">
                 查询发布记录
            </button>
            </th>
        </tr>
    </table>
    <div style="text-align:center; margin-top:10px; margin-left:-100px;" >
        <c:if test="${paging.totalPage >=0}">
            <p style=" color: black; font-size:16px; margin-bottom:10px;">当前第 ${paging.currentPage } 页/共  ${paging.totalPage} 页</p>
            <c:choose>
                <c:when test="${paging.totalPage==0}">
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(1)">首页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.currentPage-1})">上一页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.currentPage+1})">下一页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.totalPage})">末页</button>
                </c:when>
                <c:when test="${paging.currentPage==1 && paging.totalPage==1}">
                    <button class="layui-btn" onclick="goPage(1)">首页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.currentPage-1})">上一页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.currentPage+1})">下一页</button>
                    <button class="layui-btn" onclick="goPage(${paging.totalPage})">末页</button>
                </c:when>
                <c:when test="${paging.currentPage==1 && paging.totalPage>1}">
                    <button class="layui-btn" onclick="goPage(1)">首页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.currentPage-1})">上一页</button>
                    <button class="layui-btn" onclick="goPage(${paging.currentPage+1})">下一页</button>
                    <button class="layui-btn" onclick="goPage(${paging.totalPage})">末页</button>
                </c:when>
                <c:when test="${paging.currentPage>1 && paging.currentPage<paging.totalPage}">
                    <button class="layui-btn" onclick="goPage(1)">首页</button>
                    <button class="layui-btn" onclick="goPage(${paging.currentPage-1})">上一页</button>
                    <button class="layui-btn" onclick="goPage(${paging.currentPage+1})">下一页</button>
                    <button class="layui-btn" onclick="goPage(${paging.totalPage})">末页</button>
                </c:when>
                <c:when test="${paging.currentPage>1 && paging.currentPage==paging.totalPage}">
                    <button class="layui-btn" onclick="goPage(1)">首页</button>
                    <button class="layui-btn" onclick="goPage(${paging.currentPage-1})">上一页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.currentPage+1})">下一页</button>
                    <button class="layui-btn" onclick="goPage(${paging.totalPage})">末页</button>
                </c:when>
            </c:choose>
        </c:if>
    </div>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script src="/static/js/common.js"></script>
    <script>
        // 全选功能
        $("#allCheck").change(function (event) {
            console.log(event)
            if ($("#allCheck").prop("checked")) {
                console.log("改为所有选中")
                $(".checkQuestion").each(function () {
                    $(this).prop("checked", true);
                })
            } else {
                console.log("改为所有不选中")
                $(".checkQuestion").each(function () {
                    $(this).prop("checked", false);
                })
            }
        })

        function addSubject() {
            var ids = '';
            $(".checkQuestion:checked").each(function (i) {
                console.log(i + ":" + $(this).val())
                if (i == 0) {
                    ids = ids + $(this).val();
                } else {
                    ids = ids + "," + $(this).val()
                }

            })
            if (ids == '') {
                alert("没有选择试题")
                return false;
            }
            var data = {
                ids : ids,
                examId: $("#examId").val()
            }
            $.operate.post('/admin/online/examAddSubject', data, function (res) {
                console.log(JSON.stringify(res))
                window.location.reload();
            })
        }

        // 发布考试
        function sendExam() {
            var examId =  $("#examId").val();
            layer.open({
                type: 2
                ,title: false //不显示标题栏
                ,closeBtn: false
                ,area: ['700px', '500px']
                ,shade: 0.8
                ,btn: ['取消']
                ,btnAlign: 'c'
                ,moveType: 1 //拖拽模式，0或者1
                ,content: '/admin/online/sendExam?examId=' + examId
                ,success: function(layero){
                }
            });

        }

        function getExamRecord() {
            var examId =  $("#examId").val();
            layer.open({
                type: 2
                ,title: false //不显示标题栏
                ,closeBtn: false
                ,area: ['700px', '500px']
                ,shade: 0.8
                ,btn: ['取消']
                ,btnAlign: 'c'
                ,moveType: 1 //拖拽模式，0或者1
                ,content: '/admin/online/getExamRecord?examId=' + examId
                ,success: function(layero){
                }
            });

        }
        
        function goPage(page){
            var examId = $("#examId").val()
            window.location.href="<%=basePath%>admin/online/examDetail?examId="+examId + "&page=" + page;
        }

    </script>
</rapid:override>
<%@ include file="../base.jsp" %>
